<template>
  <split-pane v-if="fileTree.newChildren&&fileTree.newChildren.length>0" :key="forceKey" :default-percent="3" split="vertical" @resize="resize">
    <template slot="paneL">
      <div class="left-container">
        <template v-for="(item,key) in fileTree.newChildren" v-show="item.promise.is_display">
          <div
            :class="key==fileTree.selectKey?'file-button-box file-button-box-selected':'file-button-box'"
            @click="selectFile(0,key)"
            @contextmenu="(event)=>{rightSelectFile(0,key,event)}"
          >
            <div class="file-button-img-box ">
              <div class="file-button-img" :class="'file-button-img-'+item.inc_type" />
            </div>
            <div class="file-button-title">
              {{ item.name }}
            </div>
            <div
              v-if="item.newChildren&&item.newChildren.length>0"
              class="file-button-right"
            >
              ﹥
            </div>
          </div>
        </template>
        <v-contextmenu ref="contextmenu">
          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('view',fileTree.newChildren[fileTree.selectKey])">{{$t('bs.view')}}
          </v-contextmenu-item>
          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('download',fileTree.newChildren[fileTree.selectKey])">{{$t('bs.download')}}
          </v-contextmenu-item>

          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('copy',fileTree.newChildren[fileTree.selectKey])">复制</v-contextmenu-item>
          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('cute',fileTree.newChildren[fileTree.selectKey])">剪切</v-contextmenu-item>
          <template v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type=='dir'">
            <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey].promise.is_write==1" @click="$emit('upload',fileTree.newChildren[fileTree.selectKey])">{{$t('bs.uploadFiles')}}</v-contextmenu-item>
            <v-contextmenu-item v-else><span style="color: #dddddd;display: inline-block;width: 100%;cursor: not-allowed">{{$t('bs.uploadFiles')}}</span></v-contextmenu-item>
            <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey].promise.is_write==1" @click="$emit('paste',fileTree.newChildren[fileTree.selectKey])">粘贴</v-contextmenu-item>
            <v-contextmenu-item v-else><span style="color: #dddddd;display: inline-block;width: 100%;cursor: not-allowed">粘贴</span></v-contextmenu-item>
          </template>
          <v-contextmenu-item  @click="$emit('share',fileTree.newChildren[fileTree.selectKey])">{{$t('bs.share')}}</v-contextmenu-item>
          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('shouchang',fileTree.newChildren[fileTree.selectKey])">{{$t('bs.collect')}}</v-contextmenu-item>
          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('delete',fileTree.newChildren[fileTree.selectKey])">{{$t('bs.delete')}}</v-contextmenu-item>
          <v-contextmenu-item v-if="fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].inc_type!=='dir'" @click="$emit('history',fileTree.newChildren[fileTree.selectKey])">历史版本</v-contextmenu-item>
        </v-contextmenu>
      </div>
    </template>
    <template v-if="fileTree.selectKey!=null&&fileTree.newChildren&&fileTree.newChildren[fileTree.selectKey]&&fileTree.newChildren[fileTree.selectKey].newChildren&&fileTree.newChildren[fileTree.selectKey].newChildren.length>0" slot="paneR">
      <file-view-share :file-tree="fileTree.newChildren[fileTree.selectKey]" v-on="$listeners" />
    </template>

  </split-pane>

</template>
<script>
import splitPane from 'vue-splitpane'
import waves from '@/directive/waves'
import Template from '@/views/bs/template.vue'

export default {
  name: 'FileViewShare',
  components: { Template, splitPane },
  directives: { waves },
  props: {
    fileTree: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data: function() {
    return {
      forceKey: 0
    }
  },
  methods: {
    refirsh() {
      this.forceKey++
    },
    rightTest(item) {
      console.log(item)
    },
    handleUpload(item) {
      this.$emit('upload', item)
    },
    rightSelectFile(index, key, event) {
      event.preventDefault()
      this.fileTree.selectKey = null
      this.$nextTick(() => {
        this.fileTree.selectKey = key
      })

      const { clientX, clientY } = event
      this.$refs.contextmenu.show({ top: clientY, left: clientX })
    },
    selectFile(index, key) {
      this.fileTree.selectKey = null
      this.$nextTick(() => {
        this.fileTree.selectKey = key
        console.log(this.fileTree, this.fileTree.selectKey, this.fileTree.newChildren[this.fileTree.selectKey])
      })
    },
    resize() {

    }
  }
}
</script>

<style scoped>
.tree-container {
  margin-top: 8px;
}

.tree-container /deep/ .el-tree-node {
  position: relative;
  padding-left: 13px;
}

.tree-container /deep/ .el-tree-node:before {
  width: 1px;
  height: 100%;
  content: '';
  position: absolute;
  top: -38px;
  bottom: 0;
  left: 0;
  right: auto;
  border-width: 1px;
  border-left: 1px solid #b8b9bb;
}

.tree-container /deep/ .el-tree-node:after {
  width: 13px;
  height: 13px;
  content: '';
  position: absolute;
  left: 0;
  right: auto;
  top: 12px;
  bottom: auto;
  border-width: 1px;
  border-top: 1px solid #b8b9bb;
}

.tree-container /deep/ .el-tree > .el-tree-node:before {
  border-left: none;
}

.tree-container /deep/ .el-tree > .el-tree-node:after {
  border-top: none;
}

.tree-container /deep/ .el-tree .el-tree-node:last-child:before {
  height: 50px;
}

.tree-container /deep/ .el-tree .el-tree-node__content {
  color: #000;
  font-size: 14px;
  padding-left: 0 !important;
}

.tree-container /deep/ .el-tree .el-tree-node__children {
  padding-left: 11.5px;
}

.tree-container /deep/ .el-tree .el-tree-node__content > label.el-checkbox {
  margin: 0 5px 0 5px !important;
}

.tree-container /deep/ .el-tree .el-tree-node__expand-icon {
  position: relative;
  z-index: 99;
}

.tree-container /deep/ .el-tree .el-tree-node__expand-icon.is-leaf {
  display: none;
}

.tree-container /deep/ .el-tree .leaf-node-line {
  width: 23px;
  height: 13px;
  content: '';
  position: absolute;
  left: 13px;
  right: auto;
  top: 12px;
  bottom: auto;
  border-width: 1px;
  border-top: 1px solid #b8b9bb;
}

.tree-container /deep/ .el-tree .el-tree-node__content:has(.is-leaf) {

  margin-left: 24px !important;
}

.el-form-item__label {
  padding: 0px !important;
}

.el-drawer__header {
  margin: 0px !important;
  padding: 16px !important;
}

.demo-drawer {
  width: 300px;
}

.file-view-box {
  height: calc(100vh - 126px);
}

.filter-container {
  border-bottom: 1px solid #cccccc;
  padding: 10px 3px 0px 3px;
  overflow: hidden;
  height: 50px;
}

.file-button-box {
  height: 36px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  font-size: 12px;
  cursor: pointer;
}

.file-button-box-selected {
  background: #1067de;
  color: #ffffff !important;
}

.gwbox:hover {
  background: #dcdcdc;
}

.file-button-box:hover {
  background: #dcdcdc;
}

.file-button-box-hover {
  background: #dcdcdc;
}

.file-button-img-box {
  width: 36px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-button-title {
  display: flex;
  align-items: center;
  flex: 1;
}

.file-button-img-DWI {
  background-position: 0px -1800px;
}
.file-button-img-EPM {
  background-position: 0px -1850px;
}
.file-button-img-SPM {
  background-position: 0px -1900px;
}
.file-button-img {
  width: 16px;
  height: 16px;
  background: url('/static/icons-small.png') no-repeat;
}

.file-button-right {
  font-size: 14px;
  width: 20px;
}

.components-container {
  position: relative;
  height: calc(100vh - 126px);
  margin: 0px;
  border: 2px solid #cccccc;
}

.left-container {
  /*background-color: #F38181;*/
  overflow-y: auto;
  height: 100%;
  padding: 3px;
}

/* 自定义滚动条样式 */
::-webkit-scrollbar {
  width: 8px; /* 宽度 */
}

::-webkit-scrollbar-track {
  background-color: #f1f1f1; /* 轨道颜色 */
}

::-webkit-scrollbar-thumb {
  background-color: #dcdcdc; /* 拇指颜色 */
  border-radius: 5px; /* 圆角 */
}

::-webkit-scrollbar-thumb:hover {
  background-color: #dcdcdc; /* 鼠标悬停时的颜色 */
}

.right-container {
  background-color: #FCE38A;
  height: 200px;
}

.top-container {
  background-color: #FCE38A;
  width: 100%;
  height: 100%;
}

.bottom-container {
  width: 100%;
  background-color: #95E1D3;
  height: 100%;
}
.file-button-img-dir {
  background-position: 0px -50px;
}

.file-button-img-image {
  background-position: 0px -250px;
}

.file-button-img-music {
  background-position: 0px -350px;
}

.file-button-img-vedio {
  background-position: 0px -400px;
}

.file-button-img-txt {
  background-position: 0px -450px;
}

.file-button-img-pdf {
  background-position: 0px -500px;
}

.file-button-img-gw {
  background-position: 0px -550px;
}

.file-button-img-world {
  background-position: 0px -1500px;
}

.file-button-img-exe {
  background-position: 0px -900px;
}

.file-button-img-zip {
  background-position: 0px -1150px;
}

.file-button-img-ppt {
  background-position: 0px -1400px;
}

.file-button-img-excel {
  background-position: 0px -1450px;
}
</style>
